﻿using SwParaPlatform2.dlgUIConfig;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SwParaPlatform2.dlgFormula
{
    public partial class dlgParaSelect : Form
    {
        public string SelectedItem { get; private set; }
        public dlgParaSelect()
        {
            InitializeComponent();
            Init();
        }

        private void Init()
        {
            var UIConfigDict = UIConfigModel.Instance.GetGridDataDict();
            PopulateListBoxWithKeys(UIConfigDict);
        }

        private void PopulateListBoxWithKeys(Dictionary<string, Dictionary<string, object>> dictionary)
        {
            // 获取字典的所有键
            List<string> keysList = new List<string>(dictionary.Keys);

            // 清除ListBox中的现有项目
            ParaList.Items.Clear();

            // 将键添加到ListBox中
            ParaList.Items.AddRange(keysList.ToArray());
        }

        private void SelectAndClose()
        {
            if (ParaList.SelectedItem != null)
            {
                SelectedItem = ParaList.SelectedItem.ToString();
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else
            {
                MessageBox.Show("请选择一个参数。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            SelectAndClose();
        }

        private void ListBoxItems_DoubleClick(object sender, EventArgs e)
        {
            SelectAndClose();
        }
    }
}
